package mobilesmil.data;

import mobilesmil.activity.composer.ComposerActivity;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

/**
 * A rectangular construct within which a {@link SmilResource} will be displayed. 
 * Comprised of a unique {@link String} id, a {@link Rect} region, and a {@link Paint} color.
 */
public class SmilRegion {
	private String mId;
	private Rect mRegion;
	private Paint mColor = new Paint();
	
	/**
	 * A SMIL Region is a unique rectangular area to display resources.
	 * @param id				ID to uniquely identify this region.
	 * @param top				The y coordinate where this region will start at.
	 * @param left				The x coordinate where this region will start at.
	 * @param width				The width of this region.
	 * @param height			The height of this region.
	 */
	public SmilRegion(String id, int top, int left, int width, int height) {
		mId = id;
		mRegion = new Rect(left, top, left + width, top + height);
		if(ComposerActivity.getEditingDataSet() != null)
			mColor.setColor(ComposerActivity.getEditingDataSet().getBackgroundColor().getColor());
		else
			mColor.setColor(Color.parseColor("#000000")); // default color is black
	}
	
	/**
	 * A SMIL Region is a unique rectangular area to display resources.
	 * @param id				ID to uniquely identify this region.
	 * @param backgroundColor	The color to be used for this region in hexidecimal format. IE #ff00ff
	 * @param top				The y coordinate where this region will start at.
	 * @param left				The x coordinate where this region will start at.
	 * @param width				The width of this region.
	 * @param height			The height of this region.
	 */
	public SmilRegion(String id, String backgroundColorHexString, int top, int left, int width, int height) {
		mId = id;
		mRegion = new Rect(left, top, left + width, top + height);
		mColor.setColor(Color.parseColor(backgroundColorHexString));
	}
	
	public SmilRegion(SmilRegion region) {
		Rect rect = region.getRect();
		mId = region.getId();
		mRegion = new Rect(rect.top, rect.left, rect.width(), rect.height());
		mColor.setStyle(region.getColor().getStyle());
		mColor.setColor(region.getColor().getColor());
	}
	
	public String getId() {
		return mId;
	}
	
	public void setRect(Rect mRegion) {
		this.mRegion = mRegion;
	}

	public Rect getRect() {
		return mRegion;
	}
	
	public Paint getColor() {
		return mColor;
	}

	public void setColor(Paint mColor) {
		this.mColor = mColor;
	}
}
